﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ABulletBoom : MonoBehaviour
{
    public float boomKeepTime = 0.2f;
    private float boomTime;
    private float damage=1;


    // Start is called before the first frame update
    void Start()
    {
        boomTime = Time.time;
    }

    // Update is called once per frame
    void Update()
    {
        if (boomTime > 0 && Time.time - boomTime > boomKeepTime)
        {
            Destroy(gameObject);
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject target = collision.gameObject;
        Hit(target);
    }
    // private void OnTriggerStay2D(Collider2D other) {
    //     Debug.Log("2222222");
    //     GameObject target = other.gameObject;
    //     Hit(target);
    // }
    protected void Hit(GameObject target)
    {
        float damageResult = DamageTarget(target);
    }

    protected float DamageTarget(GameObject target)
    {
        float ret = -1;
        if (target != null)
        {
            Damageable damageable = target.GetComponent<Damageable>();
            if (damageable != null) 
            {
                ret = damageable.Damage(gameObject, this.damage);
            }
        }
        return ret;
    }
}
